<!--参数修改-子币对-->
<template>
  <div class="bg bg1">
    <scroller class="scroller">
      <div class="wrapper" v-if="pairMap">

        
        <!--参数列表-->
        <VParam class="param" ref="param" 
        v-model="senior" 
        :isModify="true"
        :isRestore="false"
        :reserves="reserves" 
        :investCoin="pairMap.investCoin" 
        :pairMap="pairMap"></VParam>

        
        <!--其他设置 2021.5.14子币对隐藏其他设置-->
        <VSet class="set" 
              ref="set"
              v-model="sets"></VSet>
        
        <div class="height80"></div>
      </div>
    </scroller>

    <!--启动-->
    <div class="ok bg3">
      <div class="ok-but main1" @click="okClick">
        <text class="font32 text1">{{T('修改参数')}}</text>
      </div>
    </div>
  </div>
</template>

<script>

//组件
import VParam from "@/up/view/VParam.vue";
import VSet from "@/up/view/VSet.vue";
//功能
import navigator from "@/_js/navigator"; 
import modal from "@/_js/modal";
import math from "@/_js/math";
import amStrategy2 from "@/strategy/amStrategy2";
import broadcast from '@/_js/broadcast';

import weexHttp from "@/_js/https"; ;
const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T('参数'));

export default {

  components: {
    VParam,
    VSet,
  },

  data() {
    return {
      T:T,
      math:math,

      executeId:'',
      strategyName:'', //策略名称
      states:undefined, //执行状态
      configMap:undefined, //执行配置

      
      /************************************ 参数设置*/
      reserves:undefined, //参数数组
      pairMap:undefined, //交易对

      /************************************ 其他设置*/
      sets:undefined, //其他设置

      /************************************ 切换选中*/
      senior: true, //true 显示参数设置
    };
  },

  mounted() {

    this.executeId = navigator.getParam('executeId');
    this.strategyName = navigator.getParam('strategyName');
    this.states = navigator.getParam('states');
    this.configMap = navigator.getParam('configMap');

    /************************************ 参数设置*/
    this.reserves = this.configMap.reserves;
    var pairMap = this.configMap.tradePairs[0];

    /************************************ 其他设置*/
    var stopProfit = this.configMap.stopProfit.length ? math.cheng(this.configMap.stopProfit, '100') : '';
    var stopLoss = this.configMap.stopLoss.length ? math.cheng(this.configMap.stopLoss, '-100') : '';

    var pauseTime = this.configMap.pauseTime;
    var stopTime = this.configMap.stopTime;

    var cancelOrder = this.configMap.cancelOrder;
    var isConvert = this.configMap.isConvert;
    
    this.sets = { 
                'isOpen':true, //true 显示
                'isEdit':true, //true 可编辑
                // 'stopProfit':stopProfit, //止盈率
                // 'stopLoss':stopLoss, //止损率

                // 'pauseTime':pauseTime, //暂停时间戳
                // 'timeStopStamp':stopTime, //终止时间戳
                
                'cancelOrder':cancelOrder, //true 撤销订单
                'isConvert':isConvert, //true 兑换币种
              }
              

    this.httpQuerySinglePair(pairMap);
  },

  methods: {

    /********************************** http*/
    //http交易对信息
    httpQuerySinglePair(pairMap) {

      modal.showLoad();
      var param = {exchangeId: pairMap.exchangeId,
                  counterCoinId: pairMap.counterCoinId,
                  baseCoinId: pairMap.baseCoinId};
      weexHttp.post("quoteV3/querySinglePair",param,true,(data) => {
          modal.hideLoad();
          if (data.status == 200) {
            data = data.data;
            pairMap = Object.assign(pairMap, data);
            pairMap['baseCoinUsdPrice'] =  math.chu(pairMap.usdPrice, pairMap.last, math.getNumber(pairMap.baseCoinDecimal));
            this.pairMap = pairMap;
          } else {
            modal.toast(data.msg);
          }
        }
      );
    },
    
    /********************************** 点击触发*/
    //修改参数
    okClick() {

      //高级设置
      if (this.$refs.param.checkError()) {
        return;
      }

      //其他设置
      if (this.$refs.set.checkError()) {
        return;
      }
      var reserves = this.$refs.param.getParam(); 
      var setMap = this.$refs.set.getParam(); 
      
      var param = {'executeId':this.executeId,
                  'executeConfig':this.configMap,
                  'states':this.states,

                  'reserves':reserves, 
                  'setMap':setMap
                  };
      amStrategy2.modifyParam(param, ()=>{
          modal.toast(T('修改成功'));
          broadcast.send(broadcast.EXECUTE_UPDATE);
          navigator.back();
      });
    }
  }
}
</script>


<style src="@/_css/style.css"></style>
<style scoped>
.scroller {
  top: 0;
  right: 0;
  left: 0;
  z-index: 9;
}
.wrapper {
  width: 750px;
}

.param{
  width: 670px;
  margin-left: 40px;
  margin-top: 60px;
}
.set {
  width: 670px;
  margin-left: 40px;
  margin-top: 30px;
}
/*************** 启动*/
.ok{
  flex-direction: row;
  justify-content: center;
  width: 750px;
  height: 164px;
}
.ok-but{
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 670px;
  height: 80px;
  border-radius: 4px;
  margin-top: 28px;
}
.height80{
  height: 80px;
}
</style>